@model Cxuu.Models.EditAdminUser
@{
    ViewData["Title"] = "个人信息";
}
<div class="content-top-nav">
    <div class="layui-row">
        <div class="layui-col-md11">
            <h3 style="color:#444">
                <i class="layui-icon layui-icon-home"></i>
                @ViewData["Title"]
            </h3>
        </div>
        <div class="layui-col-md1" style="text-align:right;">
        </div>
    </div>
    <hr>
</div>

<div class="layui-fluid" style="margin-bottom:50px;">
    <div class="layui-form">
        <form class="layui-form" action="" lay-filter="FormEdit" enctype="multipart/form-data">
            <div class="layui-form-item">
                <label class="layui-form-label"> </label>
                <div class="layui-form-mid layui-word-aux" style="color:red !important;font-size:18px;">
                    欢迎你 <span id="nickname"></span> ，祝你天天开心！万事如意！
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"> </label>
                <div class="layui-form-mid layui-word-aux" style="color:black !important;font-size:16px;">
                    部门：<span id="deptName"></span>
                    职务：<span id="postName"></span>
                    角色：<span id="groupname"></span>
                </div>
            </div>

            <div class="layui-form-item">
                <label asp-for="OldPassword" class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input type="text" asp-for="OldPassword" placeholder="请输入密码" value="" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>

            <div class="layui-form-item">
                <label asp-for="Password" class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input type="text" asp-for="Password"  placeholder="请输入新密码" value="" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">新密码为字母数字下划线及特殊字符组合,且最少6位最多20位！如不修改，可以为空！</div>
            </div>

            <div class="layui-form-item">
                <label asp-for="Nickname" class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input type="text" asp-for="Nickname" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label asp-for="Sex" class="layui-form-label"></label>
                <div class="layui-input-block">
                    <input asp-for="Sex" type="radio" value="0" title="女">
                    <input asp-for="Sex" type="radio" value="1" title="男">
                    <input asp-for="Sex" type="radio" value="2" title="中性" checked>
                </div>
            </div>

            <div class="layui-form-item">
                <label asp-for="Avatar" class="layui-form-label required"></label>
                <div class="layui-input-block" style="width:515px;">
                    <div class="layui-upload-list" style="width:420px;" id="photopre">
                        <p id="errorText"></p>
                    </div>
                    <input asp-for="Avatar" value="" class="layui-input" id="imageval" type="hidden">
                    @if (await Authorizer.AuthView(PermissionKeys.Upload_Upload))
                    {
                        <button type="button" class="layui-btn" id="thumimg">
                            <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                        <div style="width:110px;">
                            <div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="uploadText">
                                <div class="layui-progress-bar" lay-percent=""></div>
                            </div>
                        </div>
                    }
                </div>
            </div>

            <div class="layui-form-item">
                <label asp-for="Phone" class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input type="text" asp-for="Phone" lay-verify="required" lay-reqtext="联系电话不能为空" placeholder="请输入联系电话" value="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saveBtn">提交</button>
                </div>
            </div>
            <input type="hidden" asp-for="Username" value="dengzhonghua" />
        </form>
    </div>
</div>
<script>

    layui.define(function () {
        var form = layui.form, layer = layui.layer, upload = layui.upload, $ = layui.jquery, element = layui.element;

        form.render();

        var editId = @ViewBag.id+1;
        //console.log(editId);
        if (editId > 1) {
            $.getJSON("/Admin/User/UserChange?&json=1", function (res) {
                if (res.status == 1) {
                    form.val('FormEdit', {
                        //Id: res.data.id,
                        //Gid: res.data.gid,
                        //Username: res.data.username,
                        //Password: res.data.password,
                        Nickname: res.data.nickname,
                        Avatar: res.data.avatar,
                        Phone: res.data.phone,
                        //Status: res.data.status,
                    });
                    $('#nickname').html(res.data.nickname);
                    $('#deptName').html(res.data.deptName);
                    $('#groupname').html(res.data.groupname);
                    $('#postName').html(res.data.postName);
                    if(res.data.avatar != null){
                        $('#photopre').html('<img src="' + res.data.avatar + '" width="110" height="110" class="layui-circle">');
                    }else{
                        $('#photopre').html('<i class="layui-icon layui-icon-username" style="font-size: 80px; color: #1E9FFF;"></i>');
                    }

                    if (res.data.sex == 0) {
                        $('input[name="Sex"][value="0"]').prop('checked', 'checked');
                    } else if (res.data.sex == 1) {
                        $('input[name="Sex"][value="1"]').prop('checked', 'checked');
                    } else if (res.data.sex == 2) {
                        $('input[name="Sex"][value="2"]').prop('checked', 'checked');
                    }
                    form.render('radio');
                } else {
                    layer.msg("数据错误！", { icon: 2, anim: 6, time: 5000 });
                }

            })
        } else {
            layer.msg("用户错误！", { icon: 2, anim: 6, time: 5000 });
        }

        //常规使用 - 普通图片上传
        var uploadImg = upload.render({
            elem: '#thumimg'
            , size: "500"
            , accept: 'images'
           // , acceptMime: 'image/jpg, image/png'
            , exts: 'jpg|png'
            , url: '/Admin/Upload/Upload?type=layuiImg&source=User'
            , before: function (obj) {
                element.progress('uploadText', '0%'); //进度条复位
                layer.msg('上传中', { icon: 16, time: 0 });
            }
            , done: function (res) {
                //如果上传失败
                if (res.status != 1) {
                    return layer.msg('上传失败');
                }
                //上传成功的一些操作
                $('#photopre').html('<img src="' + res.data.url + '" width="150" height="150" class="layui-circle">');
                $('#imageval').val(res.data.url);
            }
            , error: function () {
                //失败状态，并实现重传
                var errorText = $('#imageval');
                imageval.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoimagevalText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
            //进度条
            , progress: function (n, elem, e) {
                element.progress('uploadText', n + '%');
                if (n == 100) {
                    layer.msg('上传完毕', { icon: 1 });
                }
            }
        });

        var dataPost = function (url, data) {
            $.post(url, data, function (res) {
                if (res.status == 1) {
                    layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                        location.href = '/Admin/Login/LoginOut';
                    });
                } else {
                    layer.msg(res.msg, { icon: 2, anim: 6, time: 5000 });
                }
            });
        }

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            dataPost('/Admin/User/UserChangePost', data.field);
            return false;
        });


    });
</script>